package com.tiny.persistence.repository.impl;

import java.util.List;
import java.util.Map;

import javax.persistence.Query;

import org.apache.log4j.Logger;

import com.tiny.persistence.domain.CompanyProfile;
import com.tiny.persistence.repository.plus.CompanyProfileRepoPlus;

/**
 * 公司简介仓储层
 * 
 * @ClassName:
 * @Description: TODO
 * @author:
 * @date: 2014年3月23日
 * 
 */
public class CompanyProfileRepoImpl extends BaseRepoImpl<CompanyProfile>
		implements CompanyProfileRepoPlus {

	private static Logger logger = Logger
			.getLogger(CompanyProfileRepoImpl.class);

	@Override
	public List<CompanyProfile> getListByCondition(Map<String, Object> condition) {
		Query query = em.createQuery("from CompanyProfile as re");

		// query.setFirstResult(arg0);
		// query.setMaxResults(arg0);

		@SuppressWarnings("unchecked")
		List<CompanyProfile> list = query.getResultList();

		logger.info("======= " + list);

		return list;
	}

	@Override
	public int getCountByCondition(Map<String, Object> condition) {

		Query query = em
				.createQuery("select count(*) from CompanyProfile as au");
		Object obj = query.getSingleResult();

		logger.info("======= count=" + obj);

		return Integer.parseInt(obj.toString());
	}

	public CompanyProfile getCompany() {
		Query query = em.createQuery("from CompanyProfile as re");
		@SuppressWarnings("unchecked")
		List<CompanyProfile> list = query.getResultList();
		if(list.size() > 0){
			return list.get(0);
		}
		return null;
	}

}
